/*
 * nxtconst.h
 *
 *  Created on: Mar 9, 2012
 *      Author: Victor Nidens victornlj@gmail.com
 *
 *	This file is part of API LEGO for CMLab based on LEGO NXT Direct Commands API
 *	by Michael Collins michaelcollins@ivorycity.com and
 *	Aran Deltac aran@arandeltac.com
 *
 *	API LEGO for CMLab is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	API LEGO for CMLab library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public License
 *	along with API LEGO for CMLab. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef NXTCONST_H_
#define NXTCONST_H_

#define uint8   uint8_t
#define int8	int8_t
#define uint16  uint16_t
#define int16	int16_t
#define uint32	uint32_t
#define int32	int32_t
#define uint64  uint64_t
#define int64	int64_t


/** RET and NORET
 *
 *	For each request of the NXT, you must specify whether you want the NXT to
 *	send a return value.
 *
 *	NXT_RET
 *	NXT_NORET
 *
 *	Use NXT_RET only when you really need a return value as it does have some
 *	overhead because it has do do a second request to retrieve response
 *	data from NXT and then parses that data.
**/

#define NXT_RET     0x00
#define NXT_NORET   0x80
#define NXT_SYSOP   0x01

/** IO Port
 *
 *	NXT_SENSOR1
 *	NXT_SENSOR2
 *	NXT_SENSOR3
 *	NXT_SENSOR4
 *
 *	NXT_MOTOR_A
 *	NXT_MOTOR_B
 *	NXT_MOTOR_C
 *	NXT_MOTOR_ALL
 *
**/

#define NXT_SENSOR_1    0x00
#define NXT_SENSOR_2    0x01
#define NXT_SENSOR_3    0x02
#define NXT_SENSOR_4    0x03

#define NXT_MOTOR_A     0x00
#define NXT_MOTOR_B     0x01
#define NXT_MOTOR_C     0x02
#define NXT_MOTOR_ALL   0xFF

/** Motor Control
 *
 *	Output mode:
 *
 *	NXT_MOTOR_ON
 *	NXT_BRAKE
 *	NXT_REGULATED
 *
 *	Output regulation modes:
 *
 *	NXT_REGULATION_MODE_IDLE
 *	NXT_REGULATION_MODE_MOTOR_SPEED
 *	NXT_REGULATION_MODE_MOTOR_SYNC
 *
 *	Output run states:
 *
 *	NXT_MOTOR_RUN_STATE_IDLE
 *	NXT_MOTOR_RUN_STATE_RAMPUP
 *	NXT_MOTOR_RUN_STATE_RUNNING
 *	NXT_MOTOR_RUN_STATE_RAMPDOWN
 *
**/

#define NXT_MOTOR_ON    0x01
#define NXT_BRAKE       0x02
#define NXT_REGULATED   0x04

#define NXT_REGULATION_MODE_IDLE          0x00
#define NXT_REGULATION_MODE_MOTOR_SPEED   0x01
#define NXT_REGULATION_MODE_MOTOR_SYNC    0x02

#define NXT_MOTOR_RUN_STATE_IDLE          0x00
#define NXT_MOTOR_RUN_STATE_RAMPUP        0x10
#define NXT_MOTOR_RUN_STATE_RUNNING       0x20
#define NXT_MOTOR_RUN_STATE_RAMPDOWN      0x40

/** Sensor Type
 *
 *	NXT_NO_SENSOR
 *	NXT_SWITCH					//touch sensor
 *	NXT_TEMPERATURE
 *	NXT_REFLECTION
 *	NXT_ANGLE					//RCX rotation sensor
 *	NXT_LIGHT_ACTIVE
 *	NXT_LIGHT_INACTIVE
 *	NXT_SOUND_DB				//sound sensor with dB scaling
 *	NXT_SOUND_DBA				//sound sensor with dBA scaling
 *	NXT_CUSTOM
 *	NXT_LOW_SPEED				//NXT I2C digital sensor
 *	NXT_LOW_SPEED_9V			//NXT I2C digital sensor with 9V power
 *	NXT_HISPEED					//NXT High Speed port (S4 Only)
 *	NXT_COLOR_FULL				//NXT 2.0 color sensor in full color mode
 *	NXT_COLOR_RED				//NXT 2.0 color sensor with red light
 *	NXT_COLOR_GREEN				//NXT 2.0 color sensor with green light
 *	NXT_COLOR_BLUE				//NXT 2.0 color sensor with blue light
 *	NXT_COLOR_BLUE				//NXT 2.0 color sensor with no light
 *	NXT_COLOR_EXIT				//NXT 2.0 color sensor internal state
 *
**/

#define NXT_NO_SENSOR             	0x00
#define NXT_SWITCH                	0x01
#define NXT_TEMPERATURE           	0x02
#define NXT_REFLECTION				0x03
#define NXT_ANGLE					0x04
#define NXT_LIGHT_ACTIVE			0x05
#define NXT_LIGHT_INACTIVE			0x06
#define NXT_SOUND_DB				0x07
#define NXT_SOUND_DBA				0x08
#define NXT_CUSTOM					0x09
#define NXT_LOW_SPEED				0x0A
#define NXT_LOW_SPEED_9V			0x0B
#define NXT_HISPEED					0x0C
#define NXT_COLOR_FULL				0x0D
#define NXT_COLOR_RED				0x0E
#define NXT_COLOR_GREEN				0x0F
#define NXT_COLOR_BLUE				0x10
#define NXT_COLOR_NONE				0x11
#define NXT_COLOR_EXIT				0x12



/** Sensor Mode
 *
 *	NXT_RAW_MODE					//Raw value from 0 to 1023
 *	NXT_BOOLEAN_MODE				//Boolean value (0 or 1)
 *	NXT_TRANSITION_CNT_MODE			//Counts the number of boolean transitions
 *
 *	NXT_PERIOD_COUNTER_MODE			//Counts the number of boolean periods
 *	NXT_PCT_FULL_SCALE_MODE			//Scaled value from 0 to 100
 *
 *	NXT_CELSIUS_MODE				//RCX temperature sensor value in Celsius
 *	NXT_FAHRENHEIT_MODE				//RCX temperature sensor value in Fahrenheits
 *
 *	NXT_ANGLE_STEPS_MODE			//RCX rotation sensor (16 ticks per revolution)
 *	NXT_SLOPE_MASK					//Mask for slope parameters added to mode
 *	NXT_MODE_MASK					//Mask for the mode without any slope value
 *
**/

#define NXT_RAW_MODE              0x00
#define NXT_BOOLEAN_MODE          0x20
#define NXT_TRANSITION_CNT_MODE   0x40

#define NXT_PERIOD_COUNTER_MODE   0x60
#define NXT_PCT_FULL_SCALE_MODE   0x80

#define NXT_CELSIUS_MODE          0xA0
#define NXT_FAHRENHEIT_MODE       0xC0

#define NXT_ANGLE_STEPS_MODE      0xE0
#define NXT_SLOPE_MASK            0x1F
#define NXT_MODE_MASK             0xE0

/** Op Codes
 *
 *	Generally you will not need to use these constants
 *	since L<LEGO::NXT> provides easy to use wrappers around
 *	all of these actions.
 *
 *	NXT_START_PROGRAM
 *	NXT_STOP_PROGRAM
 *	NXT_PLAY_SOUND_FILE
 *	NXT_PLAY_TONE
 *	NXT_SET_OUTPUT_STATE
 *	NXT_SET_INPUT_MODE
 *	NXT_GET_OUTPUT_STATE
 *	NXT_GET_INPUT_VALUES
 *	NXT_RESET_SCALED_INPUT_VALUE
 *	NXT_MESSAGE_WRITE
 *	NXT_RESET_MOTOR_POSITION
 *	NXT_GET_BATTERY_LEVEL
 *	NXT_STOP_SOUND_PLAYBACK
 *	NXT_KEEP_ALIVE
 *	NXT_LSGET_STATUS
 *	NXT_LSWRITE
 *	NXT_LSREAD
 *	NXT_GET_CURRENT_PROGRAM_NAME
 *	NXT_MESSAGE_READ
 *
**/

#define NXT_START_PROGRAM              0x00
#define NXT_STOP_PROGRAM               0x01
#define NXT_PLAY_SOUND_FILE            0x02
#define NXT_PLAY_TONE                  0x03
#define NXT_SET_OUTPUT_STATE           0x04
#define NXT_SET_INPUT_MODE             0x05
#define NXT_GET_OUTPUT_STATE           0x06
#define NXT_GET_INPUT_VALUES           0x07
#define NXT_RESET_SCALED_INPUT_VALUE   0x08
#define NXT_MESSAGE_WRITE              0x09
#define NXT_RESET_MOTOR_POSITION       0x0A
#define NXT_GET_BATTERY_LEVEL          0x0B
#define NXT_STOP_SOUND_PLAYBACK        0x0C
#define NXT_KEEP_ALIVE                 0x0D
#define NXT_LSGET_STATUS               0x0E
#define NXT_LSWRITE                    0x0F
#define NXT_LSREAD                     0x10
#define NXT_GET_CURRENT_PROGRAM_NAME   0x11
#define NXT_MESSAGE_READ               0x13

/** SYS OPCODES
 *
 *	NXT_SYS_OPEN_READ
 *	NXT_SYS_OPEN_WRITE
 *	NXT_SYS_READ
 *	NXT_SYS_WRITE
 *	NXT_SYS_CLOSE
 *	NXT_SYS_DELETE
 *	NXT_SYS_FIND_FIRST
 *	NXT_SYS_FIND_NEXT
 *	NXT_SYS_GET_FIRMWARE_VERSION
 *	NXT_SYS_OPEN_WRITE_LINEAR
 *	NXT_SYS_OPEN_READ_LINEAR
 *	NXT_SYS_OPEN_WRITE_DATA
 *	NXT_SYS_OPEN_APPEND_DATA
 *	NXT_SYS_BOOT
 *	NXT_SYS_SET_BRICK_NAME
 *	NXT_SYS_GET_DEVICE_INFO
 *	NXT_SYS_DELETE_USER_FLASH
 *	NXT_SYS_POLL_COMMAND_LENGTH
 *	NXT_SYS_POLL_COMMAND
 *	NXT_SYS_BLUETOOTH_FACTORY_RESET
 *
**/

#define NXT_SYS_OPEN_READ					0x80
#define NXT_SYS_OPEN_WRITE					0x81
#define NXT_SYS_READ						0x82
#define NXT_SYS_WRITE						0x83
#define NXT_SYS_CLOSE						0x84
#define NXT_SYS_DELETE						0x85
#define NXT_SYS_FIND_FIRST					0x86
#define NXT_SYS_FIND_NEXT					0x87
#define NXT_SYS_GET_FIRMWARE_VERSION		0x88
#define NXT_SYS_OPEN_WRITE_LINEAR			0x89
#define NXT_SYS_OPEN_READ_LINEAR			0x8A
#define NXT_SYS_OPEN_WRITE_DATA				0x8B
#define NXT_SYS_OPEN_APPEND_DATA			0x8C
#define NXT_SYS_BOOT						0x97
#define NXT_SYS_SET_BRICK_NAME				0x98
#define NXT_SYS_GET_DEVICE_INFO				0x9B
#define NXT_SYS_DELETE_USER_FLASH			0xA0
#define NXT_SYS_POLL_COMMAND_LENGTH			0xA1
#define NXT_SYS_POLL_COMMAND				0xA2
#define NXT_SYS_BLUETOOTH_FACTORY_RESET		0xA4


#endif /* NXTCONST_H_ */
